<?php
	session_start();
	error_reporting(E_ALL ^ E_NOTICE);
	
	if (($_POST['submit']) && ($_POST['act']=="langs"))
		$_SESSION['BASE_LANGUAGE'] = $_POST['language'];
	(isset($_SESSION['BASE_LANGUAGE'])) ? $langs = $_SESSION['BASE_LANGUAGE'] : $langs = 'indonesian-utf-8.inc.php';

	@chdir("../");
	define('ABS_URL',str_replace("\\","/",getcwd()));
	require ABS_URL.'/engine/Smarty.class.php';
	$smarty = new Smarty();
	require ABS_URL."/install/langs/".$langs;
	require ABS_URL."/langs/".$langs;
	require ABS_URL."/functions/class.query.inc.php";
	require ABS_URL."/functions/func_content.php";
	require ABS_URL."/functions/func_file.php";
	$queryData = new queryData();
		
	if ((!isset($_SESSION['url'])) || ($_SESSION['url']==''))
		$url = '/';
	else
		$url = $_SESSION['url'];
	
	class template {
		public $Header = 'aidiCMS (Alternative Digital Content Management System)';
		public $show = '';
		public $menuData = array();
		public $currStep = '';
		
		function header() {
			$data = '<div class="header">'.$this->header.'</div>';
			return $data;
		}
	
		function menu() {
			global $STEP_INSTALL;
			$data = $STEP_INSTALL;
			$dataArray = array('','system-initialization','database-initialization','website-initialization','summary');
			
			$data .= '<ul>';
			foreach ($this->menuData as $num => $val) {
				$data .= '<li ';
				if ($this->currStep==$dataArray[$num])
					$data .= 'class="selected"';
				elseif (($num==0) && ($this->currStep==""))
					$data .= 'class="selected"';
				$data .= '>'.$val.'</li>'; 	
			}
			$data .= '</ul>';
			$data = '<div class="menu">'.$data.'</div>';
			return $data;
		}
	
		function footer() {
			$data = '<div class="footer">'.footer().'</div>';
			return $data;
		}
		
		function cekThisData() {
			global $STEP_mySQL;
			if (isset($_SESSION['sesi_ver'])) {
				$HTML = '<div class="warning">'.$STEP_mySQL[0].'<br />';
				$HTML .= '<ul>';
				foreach ($_SESSION['sesi_ver'] as $val)	{
					$HTML .= '<li>'.$val.'</li>';
				}
				$HTML .= '</ul></div>';
			}
			unset($_SESSION['sesi_ver']);
			return $HTML;
		}
		
		function check_file_exists($filename,$comment) {
			if (is_file($filename)) {
				$file = $comment.'............ <span style="color:#0F0">[OK]</span>';				
				$file .= '<input type="hidden" name="checked_file[]" value="" />';
			} else {
				$file = $comment.'............ <span style="color:#F00">[NOT OK]</span>';
				$file .= '<input type="hidden" name="checked_file[]" value="'.$comment.'" />';
			}
			return $file;
		}
		
		function check_file_to_write($filename,$comment,$create='true') {
			if (is_file($filename)) {
				@chmod($filename,0777);
				$file = $comment.'........... <span style="color:#0F0">[OK]</span>';
				$file .= '<input type="hidden" name="checked_file[]" value="" />';
			} elseif($create=='true') {
				@file_put_contents($filename,'');
				(is_file($filename)) ? $file = $comment.'........... <span style="color:#0F0">[OK]</span>' : $file = $comment.'........... <span style="color:#F00">[NOT OK]</span>';
				$file .= '<input type="hidden" name="checked_file[]" value="'.$comment.'" />';
			} else {
				$file = $comment.'............ <span style="color:#F00">[NOT OK]</span>';
				$file .= '<input type="hidden" name="checked_file[]" value="" />';
			}
			return $file;
		}
				
		//SAMPAI STEP KEDUA - BELUM SELESAI
		function content() {
			global $STEP_WELCOME,$STEP_WELCOME_HINT,$STEP_SYSTEM,$STEP_DATABASE,$STEP_WEBSITE,$STEP_CHECK,$STEP_HINT,$url,$STEP_WRITE,$langs,$STEP_FILE,$STEP_DELETE,$STEP_WRITE_SUCCESS,$STEP_WRITE_FAILED,$STEP_CHECK_ALL_IS_OK,$IS_EXIST,$IS_READY_TO_WRITE;
			$dataHTML = '<div class="content">';
			switch ($this->show) {
				case "first" :
					$dataHTML .= '<h2>'.$STEP_SYSTEM.'</h2>';
					$dataHTML .= $this->cekThisData();
					$dataHTML .= '<form name="system" method="post">';
					$dataHTML .= '<hr />';
					$dataHTML .= $this->check_file_exists('index.php','Main File '.$IS_EXIST).'<br />';
					$dataHTML .= $this->check_file_exists('gravatar.php','Gravatar File '.$IS_EXIST).'<br />';
					$dataHTML .= $this->check_file_exists('rss.php','RSS Syndicate File '.$IS_EXIST).'<br />';
					$dataHTML .= $this->check_file_exists('modul/funct_stat.php','Admin Stats File '.$IS_EXIST).'<br />';
					$dataHTML .= $this->check_file_exists('functions/class.query.inc.php','Class Engine '.$IS_EXIST).'<br />';
					$dataHTML .= $this->check_file_exists('functions/func_content.php','Function Engine '.$IS_EXIST).'<br />';
					$dataHTML .= $this->check_file_exists('functions/func_banner.php','Banner Engine '.$IS_EXIST).'<br />';
					$dataHTML .= $this->check_file_exists('functions/code_verify.php','CAPCHA engine '.$IS_EXIST).'<br />';
					$dataHTML .= $this->check_file_exists('functions/func_file.php','File Engine '.$IS_EXIST).'<br />';
					$dataHTML .= $this->check_file_exists('functions/func_mce_like.php','Editor Engine '.$IS_EXIST).'<br />';
					$dataHTML .= $this->check_file_exists('install/sql/aidicmsv3.sql','Database File '.$IS_EXIST).'<br />';
					$dataHTML .= $this->check_file_to_write('dev_con.inc.php','Configuration File '.$IS_READY_TO_WRITE,'true').'<br />';
					$dataHTML .= $this->check_file_to_write('sitemap-index.xml','Sitemap Index File '.$IS_READY_TO_WRITE,'true').'<br />';
					$dataHTML .= $this->check_file_to_write('robots.txt','Robots File '.$IS_READY_TO_WRITE,'true').'<br />';
					$dataHTML .= $this->check_file_to_write('sitemap.xml','Sitemap File '.$IS_READY_TO_WRITE,'true').'<br />';
					$dataHTML .= $this->buttonSubmit();
					$dataHTML .= '<input name="act" type="hidden" value="system" />';
					$dataHTML .= '<hr />';
					$dataHTML .= $STEP_CHECK_ALL_IS_OK;
					$dataHTML .= '</form>';
				break;
				case "second" :
					$dataHTML .= '<h2>'.$STEP_DATABASE.'</h2>';
					$dataHTML .= $this->cekThisData();
					$dataHTML .= '<form name="database" method="post">';
					$dataHTML .= '<label>mySQL Hostname:</label><input size="18" name="hostname" type="text" class="input" value="'.$_SESSION['hostname'].'" /> '.$STEP_HINT[0].'';
					$dataHTML .= '<label>mySQL Username:</label><input size="15" name="username" type="text" class="input" value="'.$_SESSION['username'].'" /> '.$STEP_HINT[1];
					$dataHTML .= '<label>mySQL Password:</label><input size="20" name="password" type="password" class="input" value="'.$_SESSION['password'].'" /> '.$STEP_HINT[2];
					$dataHTML .= '<label>mySQL Database Name:</label><input size="20" name="database" type="text" class="input" value="'.$_SESSION['database'].'" /> '.$STEP_HINT[3];
					$dataHTML .= '<input name="act" type="hidden" value="mysql" />';
					$dataHTML .= $this->buttonSubmit();
					$dataHTML .= '</form>';
				break;
				case "third" :
					$dataHTML .= '<h2>'.$STEP_WEBSITE.'</h2>';
					$dataHTML .= $this->cekThisData();
					$dataHTML .= '<form name="website" method="post">';
					$dataHTML .= '<label>Website Title:</label><input size="55" name="title" type="text" class="input" value="'.$_SESSION['title'].'" /> '.$STEP_HINT[4];
					$dataHTML .= '<label>Website URl:</label> http://'.$_SERVER['HTTP_HOST'].' <input size="10" class="input" name="url" type="text" value="'.$url.'" /> '.$STEP_HINT[5];
					$dataHTML .= '<label>Website Admin Name:</label><input size="15" class="input" name="admin-user" type="text" value="'.$_SESSION['admin-user'].'" /> '.$STEP_HINT[6];
					$dataHTML .= '<label>Website Admin Password:</label><input size="15" name="admin-pass" class="input" type="password" type="text" value="'.$_SESSION['admin-pass'].'" /> '.$STEP_HINT[7];
					$dataHTML .= '<label>Website Admin Email:</label><input size="15" name="admin-email" class="input" type="text" type="text" value="'.$_SESSION['admin-email'].'" /> '.$STEP_HINT[8];
					$dataHTML .= '<input name="act" type="hidden" value="website" />';
					$dataHTML .= $this->buttonSubmit();
					$dataHTML .= '</form>';
				break;
				case "fourth" :
					$dataHTML .= '<h2>'.$STEP_CHECK.'</h2>';
					$dataHTML .= $this->cekThisData();
					$dataHTML .= '<ul>';
					$dataHTML .= '<li>mySQL<ul>';
					$dataHTML .= '<li><span class="variable">mySQL Hostname</span><span class="value">: '.$_SESSION['hostname'].'</span></li>';
					$dataHTML .= '<li><span class="variable">mySQL Username</span><span class="value">: '.$_SESSION['username'].'</span></li>';
					$dataHTML .= '<li><span class="variable">mySQL Password</span><span class="value">: '.preg_replace("/[aiueo0-9]/","*",$_SESSION['password']).'</span></li>';
					$dataHTML .= '<li><span class="variable">mySQL Database Name</span><span class="value">: '.$_SESSION['database'].'</span></li>';
					$dataHTML .= '</ul></li></ul><ul>';
					$dataHTML .= '<li>Website<ul>';
					$dataHTML .= '<li><span class="variable">Website Title</span><span class="value">: '.$_SESSION['title'].'</span></li>';
					$dataHTML .= '<li><span class="variable">Website URl</span><span class="value">: http://'.$_SERVER['HTTP_HOST'].$_SESSION['url'].'</span></li>';
					$dataHTML .= '<li><span class="variable">Website Admin Name</span><span class="value">: '.$_SESSION['admin-user'].'</span></li>';
					$dataHTML .= '<li><span class="variable">Website Admin Password</span><span class="value">: '.preg_replace("/[aiueo0-9]/","*",$_SESSION['admin-pass']).'</span></li>';
					$dataHTML .= '<li><span class="variable">Website Admin Email</span><span class="value">: '.$_SESSION['admin-email'].'</span></li>';
					$dataHTML .= '</ul></li></ul>';
					$dataHTML .= $STEP_WRITE;
					$dataHTML .= '<form name="website" method="post" action="'.$this->nextStep().'">';
					$dataHTML .= $this->buttonSubmit();
					$dataHTML .= '</form>';
				break;
				case "fifth" :
					$dataHTML .= '<h2>'.$STEP_FILE.'</h2>';
					$aidicms_conn = @mysql_connect($_SESSION['hostname'],$_SESSION['username'],$_SESSION['password']);
					$aidicms_db = @mysql_select_db($_SESSION['database']);
					$filename = 'aidicmsv3.sql';
					$completefilename = 'install/sql/aidicmsv3.sql';
					if (is_file($completefilename)) {
						$sql = "DROP TABLE `config`, `ikadir_kat`, `kota`, `maildata`, `mailtrack`, `modul`, `propinsi`, `tbl_content`, `tbl_hakakses`, `tbl_kategori`, `tbl_log`, `tbl_login`, `tbl_themes`, `tbl_upload`, `x_field`, `x_fieldvalue`;";
						$qry = @mysql_query($sql,$aidicms_conn);
						$fp = fopen($completefilename,'r');
						$fr = fread($fp,filesize($completefilename));
						$fr = explode(";\r\n",$fr);
						foreach($fr as $READ) {
							$qry = mysql_query($READ);
						}
					}
		
					$sql = "INSERT INTO `config` (`idconfig`, `configname`, `value`) VALUES (1, 'VERSION_CONTROL', 'v3.50'),(2, 'BASE_LANGUAGE', '".substr($langs,0,-8)."'),(3, 'ADMIN_THEMES', 'admin-v2');";
					$qry = @mysql_query($sql,$aidicms_conn);
					
					$sql = "INSERT INTO `tbl_login` (`id_user`, `namauser`, `alias`, `passuser`, `aktivasi`, `type_user`, `tanggal`, `tglupdate`) VALUES (1, 'root', '".$_SESSION['admin-user']."', '".md5($_SESSION['admin-pass'])."', '1', 'root[break]', '".date("Y-m-d H:i:s")."', '".date("Y-m-d H:i:s")."');";
					$qry = @mysql_query($sql,$aidicms_conn);
					
					$HTMLTemplate = '<?php'."\n";
					$HTMLTemplate .= '// ---------------------------------------------------------------------------'."\n";
					$HTMLTemplate .= '// Website Path'."\n";
					$HTMLTemplate .= '	// Relative path to website '."\n";
					$HTMLTemplate .= '	// ex.http://aidicms.com/aidi so aidicms_path variable must be in "/aidi/" (without quotes)'."\n";
					$HTMLTemplate .= '	$aidicms_path 			= "'.$_SESSION['url'].'";'."\n";
					$HTMLTemplate .= '	$aidicms_path_module 		= "modul/";'."\n";
					$HTMLTemplate .= '	$aidicms_path_themes 		= "themes/";'."\n";
					$HTMLTemplate .= '	$aidicms_path_data 		= "data/";'."\n";
					$HTMLTemplate .= '	$aidicms_path_abs		= str_replace("\\\", "/", dirname(__FILE__));'."\n";
					$HTMLTemplate .= ''."\n";
					$HTMLTemplate .= '// ---------------------------------------------------------------------------'."\n";
					$HTMLTemplate .= '// Database Configuration. MySQL v4 or above Only.'."\n";
					$HTMLTemplate .= '	// Database Host'."\n";
					$HTMLTemplate .= '	$aidicms_hostQ 			= "'.$_SESSION['hostname'].'";'."\n";
					$HTMLTemplate .= '	// Database User'."\n";
					$HTMLTemplate .= '	$aidicms_userQ 			= "'.$_SESSION['username'].'";'."\n";
					$HTMLTemplate .= '	// Database Password'."\n";
					$HTMLTemplate .= '	$aidicms_passQ 			= "'.$_SESSION['password'].'";'."\n";
					$HTMLTemplate .= '	// Database Name'."\n";
					$HTMLTemplate .= '	$aidicms_baseQ 			= "'.$_SESSION['database'].'";	'."\n";
					$HTMLTemplate .= ''."\n";
					$HTMLTemplate .= '//---------------------------------------------------------------------------'."\n";
					$HTMLTemplate .= '// Website Base Configuration'."\n";
					$HTMLTemplate .= '	// Website Title'."\n";
					$HTMLTemplate .= '	$aidicms_website_title		= "'.$_SESSION['title'].'";	'."\n";
					$HTMLTemplate .= '	// Website author Email'."\n";
					$HTMLTemplate .= '	$aidicms_mail			= "'.$_SESSION['admin-email'].'";'."\n";
					$HTMLTemplate .= ''."\n";
					$HTMLTemplate .= '//---------------------------------------------------------------------------'."\n";
					$HTMLTemplate .= '// Website Default Banner Configuration'."\n";
					$HTMLTemplate .= '	// Default Time a banner showed up (in day)'."\n";
					$HTMLTemplate .= '	$aidicms_lamaIklan 		= 7;'."\n";
					$HTMLTemplate .= '	// Default banner maximum post'."\n";
					$HTMLTemplate .= '	$aidicms_jum_post_iklan		= 2;'."\n";
					$HTMLTemplate .= '	// Default banner Maximum size (in byte)'."\n";
					$HTMLTemplate .= '	// 1 KB = 1024 B'."\n";
					$HTMLTemplate .= '	$aidicms_max_foto 		= 25600;'."\n";
					$HTMLTemplate .= '	// Default banner maximum width (in px)'."\n";
					$HTMLTemplate .= '	$aidicms_width_file		= 300;'."\n";
					$HTMLTemplate .= '	// Default banner thumbnail maximum width (in px)	'."\n";
					$HTMLTemplate .= '	$aidicms_width_thumb		= 100;'."\n";
					$HTMLTemplate .= ''."\n";
					$HTMLTemplate .= '// ---------------------------------------------------------------------------'."\n";
					$HTMLTemplate .= '// Website Default Paging Configuration'."\n";
					$HTMLTemplate .= '	// Default record for show'."\n";
					$HTMLTemplate .= '	$aidicms_record 		= 0;'."\n";
					$HTMLTemplate .= '	// Default record each page'."\n";
					$HTMLTemplate .= '	$aidicms_page			= 10;'."\n";
					$HTMLTemplate .= '	// Default number show after/before current page number'."\n";
					$HTMLTemplate .= '	$aidicms_next_prev 		= 4;'."\n";
					$HTMLTemplate .= ''."\n";
					$HTMLTemplate .= '// ---------------------------------------------------------------------------'."\n";
					$HTMLTemplate .= '// Do not edit'."\n";
					$HTMLTemplate .= '	$aidicms_hakakses 		= explode("|",$_SESSION["modul_access"]); '."\n";
					$HTMLTemplate .= '	$_SESSION["hasilX"] 		= array();'."\n";
					$HTMLTemplate .= '	$_SESSION["modul_access"] 	= "";'."\n";
					$HTMLTemplate .= '	$aidicms_limitdown 		= (@is_numeric($_GET["limitdown"])) ? (@abs(@strip_tags($_GET["limitdown"]))) : 0;'."\n";
					$HTMLTemplate .= '	$aidicms_baris			= 2;'."\n";
					$HTMLTemplate .= '	// SQL Mode'."\n";
					$HTMLTemplate .= '	$aidicms_important_user		= "id_user!=\'1\'";'."\n";
					$HTMLTemplate .= '	$aidicms_arrpenting 		= array();'."\n";
					$HTMLTemplate .= '	'."\n";
					$HTMLTemplate .= '	$aidicms_conn = @mysql_connect($aidicms_hostQ,$aidicms_userQ,$aidicms_passQ);	'."\n";
					$HTMLTemplate .= '	if (!$aidicms_conn) {'."\n";
					$HTMLTemplate .= '		die("tidak bisa melakukan koneksi ke database mySQL. Periksa Kembali Konfigurasi Koneksi Anda");'."\n";
					$HTMLTemplate .= '	}'."\n";
					$HTMLTemplate .= '		'."\n";
					$HTMLTemplate .= '	$aidicms_db = @mysql_select_db($aidicms_baseQ);'."\n";
					$HTMLTemplate .= '	'."\n";
					$HTMLTemplate .= '	if (!$aidicms_db) {'."\n";
					$HTMLTemplate .= '		die("tidak bisa memilih database mySQL. Periksa Kembali Konfigurasi database Anda.");'."\n";
					$HTMLTemplate .= '	};'."\n";
					$HTMLTemplate .= ''."\n";
					$HTMLTemplate .= '// Global Initialize'."\n";
					$HTMLTemplate .= '	define("HOSTNAME_WEB",$aidicms_hostQ);'."\n";
					$HTMLTemplate .= '	define("USERNAME_WEB",$aidicms_userQ);'."\n";
					$HTMLTemplate .= '	define("PASSWORD_WEB",$aidicms_passQ);'."\n";
					$HTMLTemplate .= '	define("DATABASE_WEB",$aidicms_baseQ);'."\n";
					$HTMLTemplate .= '	define("DIR_PATH",$aidicms_path);'."\n";
					$HTMLTemplate .= '	define("DIR_THEMES_PATH",$aidicms_path_themes);'."\n";
					$HTMLTemplate .= '	define("DIR_MODULE_PATH",$aidicms_path_module);'."\n";
					$HTMLTemplate .= '	define("DIR_DATA_PATH",$aidicms_path_data);'."\n";
					$HTMLTemplate .= '	define("DIR_ABS_PATH",$aidicms_path_abs);'."\n";
					$HTMLTemplate .= '	define("WEBSITE_TITLE",$aidicms_website_title);'."\n";
					$HTMLTemplate .= '	define("AUTHOR_MAIL",$aidicms_mail);'."\n";
					$HTMLTemplate .= '	define("LAMA_IKLAN",$aidicms_lamaIklan);'."\n";
					$HTMLTemplate .= '	define("JUMLAH_POST_IKLAN",$aidicms_jum_post_iklan);'."\n";
					$HTMLTemplate .= '	define("UKURAN_FILE",$aidicms_ukuran_max_foto);'."\n";
					$HTMLTemplate .= '	define("WIDTH_FILE",$aidicms_width_file);'."\n";
					$HTMLTemplate .= '	define("WIDTH_FILE_THUMB",$aidicms_width_file_thumb);'."\n";
					$HTMLTemplate .= '	define("NUMREC",$aidicms_record);'."\n";
					$HTMLTemplate .= '	define("PAGE",$aidicms_page);'."\n";
					$HTMLTemplate .= '	define("DEFSHOW",$aidicms_next_prev);'."\n";
					$HTMLTemplate .= '	define("RUSER",$aidicms_important_user);'."\n";
					$HTMLTemplate .= '	define("SHOWVIEW",strip_tags($_GET["showview"]));'."\n";
					$HTMLTemplate .= '	define("SHOW",strip_tags($_GET["show"]));'."\n";
					$HTMLTemplate .= '	define("LIMITDOWN",(int)$_GET["limitdown"]);'."\n";
					$HTMLTemplate .= '	define("ACT",strip_tags($_GET["act"]));'."\n";
					$HTMLTemplate .= '	define("ACT_VER",strip_tags($_GET["act_ver"]));'."\n";		
					$HTMLTemplate .= '// ---------------------------------------------------------------------------'."\n";
					$HTMLTemplate .= '?>';
					
					if(is_file("dev_con.inc.php")) {
						if (file_put_contents("dev_con.inc.php",$HTMLTemplate)) {
							$file = file_get_contents("dev_con.inc.php");
							$dataHTML .= $STEP_WRITE_SUCCESS;
						} else {
							$file = $HTMLTemplate;
							$dataHTML .= $STEP_WRITE_FAILED;
						}
					}
					
					$dataHTML .= '<textarea name="HTMLForm" style="width:100%" rows="17">'.$file.'</textarea>';
					$dataHTML .= $STEP_DELETE;
				break;
				default :
					$mydata = chdir('langs');
					$mydata = read_dir(getcwd());
					$dataHTML .= '<h2>'.$STEP_WELCOME.'</h2>';
					$dataHTML .= $this->cekThisData();
					$dataHTML .= '<form name="website" method="post" action="'.$this->nextStep().'">';
					$dataHTML .= '<ul><li><select name="language" class="input">';
					foreach($mydata['files'] as $val) {
						$fileinfo = file_ext($val);
						if ($fileinfo=='php') {
							$dataHTML .= '<option value="'.$val.'"';
							if ($val==$langs)
								$dataHTML .= '  selected="selected"';
							$dataHTML .= '>'.substr($val,0,-8).'</option>';
						}
					}
					$dataHTML .= '</select></li></ul>';
					$dataHTML .= $this->buttonSubmit();
					$dataHTML .= '<input name="act" type="hidden" value="langs" /></form>';
					$dataHTML .= '<hr />';
					$dataHTML .= $STEP_WELCOME_HINT;
				break;
			}
			$dataHTML .= '</div>';
			return $dataHTML;
		}
		
		function prevStep() {
			switch ($this->currStep) {
				case "final-install":
					$data = 'index.php?show=fourth&showview=summary';
				break;
				case "summary":
					$data = 'index.php?show=third&showview=website-initialization';
				break;
				case "website-initialization":
					$data = 'index.php?show=second&showview=database-initialization';
				break;
				case "database-initialization":
					$data = 'index.php?show=first&showview=system-initialization';
				break;
				case "system-initialization":
					$data = 'index.php';
				break;
				default:
					$data = 'index.php';
				break;
			}
			return $data;
		}
		
		function nextStep() {
			switch ($this->show) {
				case "fifth":
					$data = '';
				break;
				case "fourth":
					$data = 'index.php?show=fifth&showview=final-install';
				break;
				case "third":
					$data = 'index.php?show=fourth&showview=summary';
				break;
				case "second":
					$data = 'index.php?show=third&showview=website-initialization';
				break;
				case "first":
					$data = 'index.php?show=second&showview=database-initialization';
				break;
				default:
					$data = 'index.php?show=first&showview=system-initialization';
				break;
			}
			return $data;
		}
		
		function buttonSubmit() {
			global $DEV_ADMIN_PREV,$DEV_ADMIN_NEXT,$STEP_BUTTON_WRITE;
			$data = '<div class="nextPrev">';
			if ($this->currStep=="")
				$data .= '<input name="submit" type="submit" class="submit" value="'.$DEV_ADMIN_NEXT.'" />';
			elseif ($this->currStep=='summary')
				$data .= '<input name="back" type="button" class="submit" value="'.$DEV_ADMIN_PREV.'" onclick="goto(\''.$this->prevStep().'\')" /> <input name="submit" type="submit" class="submit" value="'.$STEP_BUTTON_WRITE.'" />';
			else
				$data .= '<input name="back" type="button" class="submit" value="'.$DEV_ADMIN_PREV.'" onclick="goto(\''.$this->prevStep().'\')" /> <input name="submit" type="submit" class="submit" value="'.$DEV_ADMIN_NEXT.'" />';
			$data .= '</div>';
			return $data;
		}
	}
	
	$templateHTML = new template();	
	$templateHTML->currStep = $_GET['showview'];
	$templateHTML->menuData = $STEP_INSTALL_ARRAY;
	$templateHTML->show = strip_tags($_GET['show']);
	
	if (($_POST['submit']) && ($_POST['act']=='system')) {
		if (is_array($_POST['checked_file'])) {
			foreach($_POST['checked_file'] as $val) {
				if (!empty($val))
					$result[] = str_replace("exist","not exist",$val);
			}
		}
		if (empty($result)) {
			header("Location:".$templateHTML->nextStep());
		} else {
			$_SESSION['sesi_ver'] = $result;
		}
	}
	
	
	if (($_POST['submit']) && ($_POST['act']=='mysql')) {
		$a = array($_POST['hostname'],$_POST['username'],$_POST['database']);
		$b = array('empty','empty','empty');
		$c = array($STEP_mySQL[1],$STEP_mySQL[2],$STEP_mySQL[3]);
		$result = $queryData->NotificationCheck($a,$b,$c);
		$_SESSION['hostname'] = $_POST['hostname'];
		$_SESSION['username'] = $_POST['username'];
		$_SESSION['password'] = $_POST['password'];
		$_SESSION['database'] = $_POST['database'];
		$_SESSION['sesi_ver'] = $result;
		if (empty($result)) {
			$aidicms_conn = @mysql_connect($a[0],$a[1],$_POST['password']);
			if ($aidicms_conn) {
				$aidicms_db = @mysql_select_db($a[2]);
				if ($aidicms_db)
					header("Location:".$templateHTML->nextStep());
				else {
					$result[0]  = $STEP_DATABASE_FAILED;
					$_SESSION['sesi_ver'] = $result;
				}
			} else {
				$result[0]  = $STEP_CONNECTION_FAILED;
				$_SESSION['sesi_ver'] = $result;
			}
		}
	}
	
	if (($_POST['submit']) && ($_POST['act']=='website')) {
		$a = array($_POST['title'],$_POST['url'],$_POST['admin-user'],$_POST['admin-pass'],$_POST['admin-email']);
		$b = array('empty','empty','empty','empty','dataemail');
		$c = array($STEP_mySQL[4],$STEP_mySQL[5],$STEP_mySQL[6],$STEP_mySQL[7],$STEP_mySQL[8]);
		$result = $queryData->NotificationCheck($a,$b,$c);
		$_SESSION['title'] = $_POST['title'];
		$_SESSION['url'] = $_POST['url'];
		$_SESSION['admin-user'] = $_POST['admin-user'];
		$_SESSION['admin-pass'] = $_POST['admin-pass'];
		$_SESSION['admin-email'] = $_POST['admin-email'];
		$_SESSION['sesi_ver'] = $result;
		if (empty($result)) {
			header("Location:".$templateHTML->nextStep());	
		}
	}
	
	$arr1 = array("[CONTENT]","[HEADER]","[MENU]","[FOOTER]");
	$arr2 = array($templateHTML->content(),$templateHTML->header(),$templateHTML->menu(),$templateHTML->footer());
	
	ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Install Sistem - aidiCMS</title>
<link rel="stylesheet" type="text/css" media="screen" href="style.css" />
<script language="javascript">
	function goto(param) {
		window.location.href=param;	
	}
</script>
</head>
<body>
[HEADER]
[MENU]
[CONTENT]
[FOOTER]
</body>
</html>
<?php
	$html = ob_get_contents();
	ob_end_clean();
	$html = str_replace($arr1,$arr2,$html);
	echo $html;
?>